import Vue from 'vue'
import Router from 'vue-router'
import iView from 'iview'
//import Util from '../util/myUtil'

Vue.use(Router)

let Admin = (resolve) => require(['../Admin.vue'], resolve)

//登录页面
let Login = (resolve) => require(['views/Login.vue'], resolve)

//用户管理
let UserList = (resolve) => require(['views/user/UserList.vue'], resolve)

//售后管理
let AfterService = (resolve) => require(['views/service/AfterService.vue'], resolve)

//轮播管理
let Banner = (resolve) => require(['views/banner/Banner.vue'], resolve)

//系统管理
let FeedbackList = (resolve) => require(['views/system/FeedbackList.vue'], resolve)

//资源管理
let ResourceCates = (resolve) => require(['views/resource/Categories.vue'], resolve)
let Resource = (resolve) => require(['views/resource/Resource.vue'], resolve)
let Product = (resolve) => require(['views/resource/CouponList.vue'], resolve)

//订单管理
let OrderList = (resolve) => require(['views/order/Order.vue'], resolve)

let routes = [
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '用户登录'
    },
    component: Login
  },
  {
    path: '/',
    component: Admin,
    children: [
      {
        path: '',
        name: 'index',
        meta: {
          title: '后台首页'
        },
        redirect: '/user',
        component: UserList
      },
      {
        path: 'user',
        name: 'UserList',
        meta: {
          title: '所有用户'
        },
        component: UserList
      },
      {
        path: 'afterservice',
        name: 'AfterService',
        meta: {
          title: '售后列表'
        },
        component: AfterService
      },
      {
        path: 'banner',
        name: 'Banner',
        meta: {
          title: '轮播管理'
        },
        component: Banner
      },
      {
        path: 'feedback',
        name: 'FeedbackList',
        meta: {
          title: '反馈列表'
        },
        component: FeedbackList
      },
      {
        path: 'resourcecates',
        name: 'ResourceCates',
        meta: {
          title: '资源分类列表'
        },
        component: ResourceCates
      },
      {
        path: 'resource',
        name: 'Resource',
        meta: {
          title: '资源列表'
        },
        component: Resource
      },
      {
        path: 'coupon',
        name: 'Coupon',
        meta: {
          title: '优惠券列表'
        },
        component: Product
      },
      {
        path: 'order',
        name: 'Order',
        meta: {
          title: '订单列表'
        },
        component: OrderList
      }
    ]
  }
]

const router = new Router({
  routes,
  linkActiveClass: 'active',
  mode: 'history'
})

router.beforeEach((to, from, next) => {
  iView.LoadingBar.start();
  // Util.title(to.meta.title);
  //window.document.title='转塘劳动和谐'
  next();
});

router.afterEach((to, from, next) => {
  iView.LoadingBar.finish();
  window.scrollTo(0, 0);
});

export default router
